package com.inmobi.commons.internal;

import android.content.Context;
import com.inmobi.commons.thinICE.cellular.CellOperatorInfo;
import com.inmobi.commons.thinICE.cellular.CellUtil;
import com.inmobi.commons.thinICE.icedatacollector.Sample;
import com.inmobi.commons.thinICE.icedatacollector.ThinICEConfigSettings;
import com.inmobi.commons.thinICE.wifi.WifiInfo;
import com.inmobi.commons.uid.UIDUtil;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONPayloadCreator
  implements PayloadCreator
{
  private JSONObject a(Sample paramSample, ThinICEConfig paramThinICEConfig)
  {
    try
    {
      JSONObject localJSONObject1 = new JSONObject();
      if (paramThinICEConfig.k)
        localJSONObject1.put("c-ap", a(paramSample.connectedWifiAp));
      if (paramThinICEConfig.j)
        localJSONObject1.put("c-sid", paramSample.servingCellId);
      JSONArray localJSONArray;
      if (paramThinICEConfig.l)
      {
        localJSONArray = new JSONArray();
        if (paramSample.visibleWifiAp != null)
          break label109;
      }
      while (true)
      {
        if (localJSONArray.length() > 0)
          localJSONObject1.put("v-ap", localJSONArray);
        if (localJSONObject1.length() <= 1)
          break;
        localJSONObject1.put("ts", paramSample.utc);
        return localJSONObject1;
        label109: Iterator localIterator = paramSample.visibleWifiAp.iterator();
        while (localIterator.hasNext())
        {
          JSONObject localJSONObject2 = a((WifiInfo)localIterator.next());
          if (localJSONObject2 != null)
            localJSONArray.put(localJSONObject2);
        }
      }
    }
    catch (JSONException localJSONException)
    {
      return null;
    }
    return null;
  }

  private JSONObject a(WifiInfo paramWifiInfo)
  {
    JSONObject localJSONObject = new JSONObject();
    try
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Long.valueOf(paramWifiInfo.bssid);
      localJSONObject.put("bssid", String.format("0x%012x", arrayOfObject));
      localJSONObject.put("essid", paramWifiInfo.ssid);
      localJSONObject.put("rssi", paramWifiInfo.rssi);
      return localJSONObject;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public String toPayloadString(List<Sample> paramList, Context paramContext)
  {
    JSONObject localJSONObject = new JSONObject();
    JSONArray localJSONArray = new JSONArray();
    ThinICEConfig localThinICEConfig = InternalSDKUtil.a.getTic();
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext())
      localJSONArray.put(a((Sample)localIterator.next(), localThinICEConfig));
    try
    {
      if (localJSONArray.length() > 0)
        localJSONObject.put("payload", localJSONArray);
      CellOperatorInfo localCellOperatorInfo = CellUtil.getCellNetworkInfo(paramContext);
      if ((!ThinICEConfigSettings.bitTest(localThinICEConfig.g, 1)) && ((localCellOperatorInfo.simMcc != -1) || (localCellOperatorInfo.simMnc != -1)))
        localJSONObject.put("s-ho", localCellOperatorInfo.simMcc + "_" + localCellOperatorInfo.simMnc);
      if ((!ThinICEConfigSettings.bitTest(localThinICEConfig.g, 2)) && ((localCellOperatorInfo.currentMcc != -1) || (localCellOperatorInfo.currentMnc != -1)))
        localJSONObject.put("s-co", localCellOperatorInfo.currentMcc + "_" + localCellOperatorInfo.currentMnc);
      Calendar localCalendar = Calendar.getInstance();
      System.currentTimeMillis();
      localJSONObject.put("tz", localCalendar.get(15));
      localJSONObject.put("ts", localCalendar.getTimeInMillis());
      UIDUtil.bindToJSON(UIDUtil.getMap(paramContext, null), localJSONObject);
      return localJSONObject.toString();
    }
    catch (JSONException localJSONException)
    {
      Log.debug("IMCOMMONS_3.7.0", "Unable to create payload for sending ThinICE params");
    }
    return null;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.commons.internal.JSONPayloadCreator
 * JD-Core Version:    0.6.2
 */